/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package logica;

/**
 *
 * @author Meme
 */
public class StructureManager {
    private java.util.ArrayList<String> names;
    private java.util.ArrayList<ItemRatingRestaurant> restaurants;
    
    public StructureManager() {
        names = new java.util.ArrayList();
        restaurants = new java.util.ArrayList();        
    }
    
    public void addRestaurant(String nombre) {
        names.add(nombre);
        restaurants.add(new ItemRatingRestaurant());
    }
    
    public java.util.ArrayList<String> getRestaurantNames() {
        return names;
    }
    
    public void addRatingToRestaurant(int index, ItemRating rating) {
        ItemRatingRestaurant tmprest = restaurants.get(index);
        tmprest.addRating(rating);
    }
    
    public java.util.ArrayList<ItemRating> getRatingsFromRestaurant(int index) {
        ItemRatingRestaurant tmprest = restaurants.get(index);
        return tmprest.getRatings();
    }

    public java.util.ArrayList<ItemRating> getRatingsFromRestaurant(String name) {
        int index = 0;
        int length = names.size();
        String tmpname;
        
        while (index < length) {
            tmpname = names.get(index);
            if (tmpname.compareTo(name) == 0)
                return restaurants.get(index).getRatings();
            
            index++;
        }
        
        return null;
    }

    public int getAverageFromRestaurant(int index) {
        ItemRatingRestaurant tmprest = restaurants.get(index);
        return tmprest.getAverage();
    }

    public int getAverageFromRestaurant(String name) {
        int index = 0;
        int length = names.size();
        String tmpname;
        
        while (index < length) {
            tmpname = names.get(index);
            if (tmpname.compareTo(name) == 0)
                return restaurants.get(index).getAverage();
            
            index++;
        }
        
        return 0;
    }    
    
    public int getIdRestaurant(String name) {
        int index = 0;
        int length = names.size();
        String tmpname;
        
        while (index < length) {
            tmpname = names.get(index);
            if (tmpname.compareTo(name) == 0)
                return index+1;
            
            index++;
        }
        
        return 0;        
    }
    
    public void addRatingToAverageRestaurant(int index, int punteo) {
        ItemRatingRestaurant tmprest = restaurants.get(index);
        tmprest.addToTotal(punteo);
    }
}
